package o;

import android.text.TextUtils;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import com.huawei.appgallery.forum.base.card.bean.ImageInfo;
import com.huawei.appgallery.forum.base.card.bean.Post;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class bzr {
    public static List<byf> ˊ(Post post) {
        if (post == null) {
            throw new NullPointerException("post is null!");
        }
        String ॱ = post.ॱ();
        List<byf> arrayList = new ArrayList();
        int i = 0;
        while (i == 0) {
            CharSequence substring;
            CharSequence charSequence;
            int i2;
            CharSequence charSequence2;
            Matcher matcher = Pattern.compile("\\[((?i)img)\\](\\d+)\\[\\/((?i)img)\\]|\\[((?i)clink)=([0-9a-zA-Z]{1}_(C|SC|H|E)?\\d+)\\](.*?)\\[\\/((?i)clink)\\]").matcher(ॱ);
            if (matcher.find()) {
                int start = matcher.start();
                int end = matcher.end();
                if (!ॱ.substring(0, start).isEmpty()) {
                    ˏ(arrayList, ॱ.substring(0, start));
                }
                if (matcher.group(1) != null && "img".equals(matcher.group(1).toLowerCase(Locale.US))) {
                    ˊ(post, arrayList, matcher);
                } else if (matcher.group(4) != null && "clink".equals(matcher.group(4).toLowerCase(Locale.US))) {
                    ˋ(arrayList, matcher);
                }
                substring = ॱ.substring(end);
                if (TextUtils.isEmpty(substring)) {
                    i = 1;
                }
                charSequence = substring;
                i2 = i;
                charSequence2 = charSequence;
            } else {
                ˏ(arrayList, ॱ);
                Object obj = ॱ;
                i2 = 1;
            }
            charSequence = charSequence2;
            i = i2;
            substring = charSequence;
        }
        return arrayList;
    }

    private static void ˊ(Post post, List<byf> list, Matcher matcher) {
        Object group = matcher.group(2);
        if (!TextUtils.isEmpty(group)) {
            try {
                long parseLong = Long.parseLong(group);
                Map ॱ = ॱ(post.ॱॱ());
                if (ॱ.containsKey(Long.valueOf(parseLong))) {
                    byl o_byl = new byl(parseLong, ((ImageInfo) ॱ.get(Long.valueOf(parseLong))).ˋ());
                    o_byl.ʻ(((ImageInfo) ॱ.get(Long.valueOf(parseLong))).ˊ());
                    o_byl.ˎ(((ImageInfo) ॱ.get(Long.valueOf(parseLong))).ˎ());
                    o_byl.ˊ(((ImageInfo) ॱ.get(Long.valueOf(parseLong))).ˏ());
                    list.add(new byf(o_byl));
                }
            } catch (NumberFormatException e) {
                bqx.ॱ("PostDetailUtil", "String to long error");
            }
        }
    }

    private static void ˋ(List<byf> list, Matcher matcher) {
        String[] split = matcher.group(5).split("_");
        list.add(new byf(new byh(Integer.parseInt(split[0]), split[1], matcher.group(7))));
    }

    private static void ˏ(List<byf> list, String str) {
        list.add(new byf(str.replace("[br]", "\n")));
    }

    public static void ˏ(List<byf> list, Post post, String str, String str2) {
        if (list != null && !list.isEmpty() && post != null) {
            List arrayList = new ArrayList();
            for (byf o_byf : list) {
                if (o_byf.ॱ() == 0) {
                    ImageInfo imageInfo = new ImageInfo();
                    imageInfo.ˊ(o_byf.ˎ().ʽ());
                    imageInfo.ˏ(o_byf.ˎ().ʽ());
                    imageInfo.ˊ(o_byf.ˎ().ˏॱ());
                    imageInfo.ˋ(o_byf.ˎ().ͺ() + "_" + o_byf.ˎ().ॱˊ());
                    arrayList.add(imageInfo);
                }
            }
            post.ˏ(str);
            post.ˏ(arrayList);
            post.ॱ(str2);
            post.ॱ(0);
        }
    }

    public static void ॱ(byg o_byg, Post post) {
        if (o_byg != null && post != null) {
            post.ˏ(o_byg.ˊ());
            if (o_byg.ॱ() != null) {
                List arrayList = new ArrayList();
                ImageInfo imageInfo = new ImageInfo();
                imageInfo.ˊ(o_byg.ॱ().ʽ());
                imageInfo.ˏ(o_byg.ॱ().ʽ());
                imageInfo.ˊ(o_byg.ॱ().ˏॱ());
                imageInfo.ˋ(o_byg.ॱ().ͺ() + "_" + o_byg.ॱ().ॱˊ());
                arrayList.add(imageInfo);
                post.ˏ(arrayList);
                return;
            }
            post.ˏ(null);
        }
    }

    public static void ˎ(ImageView imageView, String str) {
        if (imageView != null && !TextUtils.isEmpty(str)) {
            LayoutParams layoutParams = imageView.getLayoutParams();
            if (layoutParams.height > 4096) {
                imageView.setScaleType(ScaleType.FIT_START);
                layoutParams.height = 4096;
                imageView.setLayoutParams(layoutParams);
            }
            if (bsx.ˎ(str)) {
                bsx.ˎ(imageView, str);
            } else {
                bsx.ॱ(imageView, str);
            }
        }
    }

    public static void ˋ(ImageView imageView, String str, int i) {
        if (imageView != null && !TextUtils.isEmpty(str)) {
            LayoutParams layoutParams = imageView.getLayoutParams();
            if (layoutParams.height > i) {
                imageView.setScaleType(ScaleType.FIT_START);
                layoutParams.height = i;
                imageView.setLayoutParams(layoutParams);
            }
            if (bsx.ˎ(str)) {
                bsx.ˎ(imageView, str);
            } else {
                bsx.ॱ(imageView, str);
            }
        }
    }

    private static Map<Long, ImageInfo> ॱ(List<ImageInfo> list) {
        Map<Long, ImageInfo> hashMap = new HashMap();
        if (list != null) {
            for (ImageInfo imageInfo : list) {
                hashMap.put(Long.valueOf(imageInfo.ॱ()), imageInfo);
            }
        }
        return hashMap;
    }
}
